<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2016/9/27
 * Time: 17:11
 */

namespace Admin\Controller;
use Component\AdminController;

class ZaifuqiyeController extends AdminController
{
    //增加企业基本信息
    public function append()
    {


        if (IS_POST) {
            $model = M('gz007f');
            $data = $model->create();
            $res = $model->add();
            if ($res) {
                $info = $model->select();
                $this->assign("info",$info);
                $this->display("append");
                echo "<script type='text/javascript'>{alert('数据添加成功');}</script>";
                // echo "<script type='text/javascript'>alert('数据添加成功');history.back(-1);</script>";
            } else {
                echo "<script type='text/javascript'>alert('数据添加失败');history.back(-1);</script>";
            }
            return;
        }
        $this->display();
    }

    //查询角色，查询所有在孵企业基本信息（采用分页形式）
    function showlist(){

        $model = D("gz007f");

        //1. 获得当前记录总条数
        $total = $model -> count();
        $per = 7;
        //2. 实例化分页类对象
        $page = new \Component\Page($total, $per); //autoload
        //3. 拼装sql语句获得每页信息
        $sql = "SELECT * FROM `gz007f` ".$page->limit;
        $info = $model -> query($sql);
        //4. 获得页码列表
        $pagelist = $page -> fpage();

        $this -> assign('info', $info);
        $this -> assign('pagelist', $pagelist);
        $this -> display();
    }
    //根据用户的身份判断其所在公司，只显示其自己公司信息
    public function showlist0($mg_com){
        $model = M('gz007f');
        //  $sql = "select * from sw_manager where mg_id=".$_SESSION['mg_id'];

//        $sql = "select * from gq006 where gq006.QA04==".$_COOKIE['mg_com'];
        $sql = "select * from `gz007f` where `gz007f`.TDF730='$mg_com'";
//print_r($sql);
        $info = $model->query($sql);
        //print_r($info);

        $this -> assign('info', $info);
        $this -> display();
    }


    //企业填报人查询某一个在孵企业的全部信息
    function showlistall($mg_com){
        //$goods = D("Cominfo");
        $goods = D();

        //拼装sql语句获得每页信息
//        $sql = "select * from gq001,gq002,gq003,gq004,gq005 ,gq006 where gq001.GQ006_ID=$GQ006_ID and gq002.GQ006_ID=$GQ006_ID 
//                and gq003.GQ006_ID=$GQ006_ID and gq004.GQ006_ID=$GQ006_ID and gq005.GQ006_ID=$GQ006_ID and gq006.GQ006_ID=$GQ006_ID";
//print_r($sql);
        $sql = "select * from `gz007f` where `gz007f`.TDF730='$mg_com'";
        $info = $goods -> query($sql);
        //print_r($info);
        $this -> assign('info', $info);
        $this -> display();

    }

    //企业填报人修改自己的在孵企业基本情况

    function upd($GZ007F_ID){
        //查询被修改商品的信息并传递给模板展示
        $model = D("gz007f");
        //两个逻辑：展示表单、收集表单
        if(IS_POST){
            $model -> create();
            $rst = $model -> save();
            if($rst){
                echo "<script type='text/javascript'>alert('数据修改成功');history.back(-1);</script>";;
            } else {
                echo "<script type='text/javascript'>alert('数据修改失败');history.back(-1);</script>";
            }
        } else {
            $info = $model->find($GZ007F_ID); //一维数组
          //  print_r($info);
            $this -> assign('info', $info);
            $this -> display();
        }
    }

    //删除在孵企业情况
    function del($GZ007F_ID)
    {
        //查询被修改商品的信息并传递给模板展示
        $model = D("gz007f");

        $res = $model->delete($GZ007F_ID);

        if ($res) {
            //echo "<script type='text/javascript'>window.onload=function(){alert('数据删除成功');}</script>";
//            $info = $model->select();
//            $this->assign("info", $info);
//            $this->display("showlist0");

            echo "<script type='text/javascript'>{alert('数据删除成功');history.back(-1);}</script>";
            //$this->showlist();
            //$this->success('删除成功');

        } else {
            echo "<script type='text/javascript'>alert('数据删除失败');history.back(-1);</script>";
        }
    }



    //导出在孵（毕业）企业情况表格
    public function output()
    {
//获取所需数据
        $res = M('gz007f')->select();
        if (IS_POST) {
            $xlsName = "在孵（毕业）企业情况列表";//表名
            $xlsCell = array(
                array('TDF730', '企业名称(TDF730)'),
                array('TDF7L108', '组织机构代码（TDF7L108）') ,
                array('TDF7L100', '企业成立时间（TDF7L100）') ,
                array('TDF7L101', '企业入驻时间（TDF7L101）'),

                array('TDF7L103', '企业登记注册类型（TDF7L103）'),
                array('TDF7L104', '行业类别（TDF7L104）'),
                array('TDF731', '企业所属技术领域(TDF731)'),
                array('TDF7L116', '企业纳税人类型(TDF7L116)'),
                array('TDF7L113', '与创业导师建立辅导关系(TDF7L113）'),

                array('TDF7L112', '毕业企业(TDF7L112）'),
                array('TDF7L105', '是否高新技术企业(TDF7L105）'),
                array('TDF7L17', '企业主要负责人创业特征(TDF7L17)'),
                array('TFH7L18', '企业主要负责人是否为连续创业者(TFH7L18）'),
                array('TDF7L102', '获天使或风险投资额（TDF7L102）（千元）'),

                array('TDF7L109', '占用孵化器场地面积（TDF7L109）（平方米）'),
                array('TDF7L110', '企业成立时注册资本（TDF7L110）（千元）'),
                array('TDF7G210', '总收入（TDF7G210）（千元）'),
                array('TDF7G230', '净利润（TDF7G230）（千元）'),
                array('TDF7G250', '出口创汇（TDF7G250）（千美元）'),

                array('TDF7G251', 'R&D投入（TDF7G251）（千元）'),
                array('TDF7G252', '实际上缴税费（TDF7G252）（千元）'),
                array('TDF7F600', '从业人员(TDF7F600)（人）'),
                array('TDF7F601', '其中：博士(TDF7F601)（人）'),
                array('TDF7F604', '大专以上(TDF7F604)（人）'),

                array('TDF7F603', '留学人员(TDF7F603)（人）'),
                array('TDF7F606', '千人计划人数(TDF7F606)（人）'),
                array('TDF7F607', '吸纳应届大学毕业生(TDF7F607)（人）'),
                array('TDF7K500', '当年知识产权申请数（TDF7K500）（件）'),
                array('TDF7K502', '当年知识产权授权数(TDF7K502)（件）'),

                array('TDF7K503', '其中：发明专利(TDF7K503)（件）'),
                array('TDF7K516', '拥有有效知识产权数(TDF7K516)（件）'),
                array('TDF7K517', '其中：发明专利(TDF7K517)（件）'),
                array('TDF7K518', '软件著作权(TDF7K518)（件）'),
                array('TDF7K519', '植物新品种(TDF7K519)（个）'),

                array('TDF7K520', '集成电路布图(TDF7K520)（个）'),
                array('TDF7K504', '购买国外专利（TDF7K504）（件）'),
                array('TDF7K508', '技术合同交易数量（TDF7K508）（项）'),
                array('TDF7K509', '技术合同交易额（TDF7K509）（千元）'),
                array('TDF7K510', '当年承担国家级科技计划项目（TDF7K510）（项）'),

                array('TDF7K512', '当年获得省级以上奖励（TDF7K512）（项）'),



            );
            $xlsData = array();
            foreach ($res as $key => $val) {
                array_push($xlsData, array(//这里的需要导出的内容，要注意键名跟上面的字段键名要一致
                    // 'QA04' => $val[GQ006_ID],
                    'TDF730' => $val[TDF730],
                    'TDF7L108' => $val[TDF7L108],
                    'TDF7L100' => $val[TDF7L100],
                    'TDF7L101' => $val[TDF7L101],

                    'TDF7L103' => $val[TDF7L103],
                    'TDF7L104' => $val[TDF7L104],
                    'TDF731' => $val[TDF731],
                    'TDF7L116' => $val[TDF7L116],
                    'TDF7L113' => $val[TDF7L113],

                    'TDF7L112' => $val[TDF7L112],
                    'TDF7L105' => $val[TDF7L105],
                    'TDF7L17' => $val[TDF7L17],
                    'TFH7L18' => $val[TFH7L18],
                    'TDF7L102' => $val[TDF7L102],

                    'TDF7L109' => $val[TDF7L109],
                    'TDF7L110' => $val[TDF7L110],
                    'TDF7G210' => $val[TDF7G210],
                    'TDF7G230' => $val[TDF7G230],
                    'TDF7G250' => $val[TDF7G250],

                    'TDF7G251' => $val[TDF7G251],
                    'TDF7G252' => $val[TDF7G252],
                    'TDF7F600' => $val[TDF7F600],
                    'TDF7F601' => $val[TDF7F601],
                    'TDF7F604' => $val[TDF7F604],

                    'TDF7F603' => $val[TDF7F603],
                    'TDF7F606' => $val[TDF7F606],
                    'TDF7F607' => $val[TDF7F607],
                    'TDF7K500' => $val[TDF7K500],
                    'TDF7K502' => $val[TDF7K502],

                    'TDF7K503' => $val[TDF7K503],
                    'TDF7K516' => $val[TDF7K516],
                    'TDF7K517' => $val[TDF7K517],
                    'TDF7K518' => $val[TDF7K518],
                    'TDF7K519' => $val[TDF7K519],

                    'TDF7K520' => $val[TDF7K520],
                    'TDF7K504' => $val[TDF7K504],
                    'TDF7K508' => $val[TDF7K508],
                    'TDF7K509' => $val[TDF7K509],
                    'TDF7K510' => $val[TDF7K510],

                    'TDF7K512' => $val[TDF7K512],






                ));
            }

            exportExcel($xlsName, $xlsCell, $xlsData);//这里就是调用写在function里的函数了。
        }
        die();
    }


}